﻿using Microsoft.VisualStudio.TestTools.UnitTesting;
using Vtron.HipcConfigurationTools.Core;
using Vtron.HipcConfigurationTools.Domain;

namespace Vtron.HipcConfigurationTools.Test
{
    /// <summary>
    /// 编解码板公用API接口测试
    /// </summary>
    [TestClass]
    public class CommonAPIUnitTest
    {
        [TestInitialize]
        public void Init()
        {
            Utils.IP = "10.4.1.173";
            Utils.PORT = 5001;
        }

        /// <summary>
        /// 消息		获取系统参数信息
        /// ID	请求:0x8400 应答：0x8401
        /// 方向	web，HipCodec->编码盒，解码盒
        /// 参数	HIPC_CMD_SYS_CONFIG_GET_REQ
        /// HIPC_CMD_SYS_CONFIG_GET_RESP
        /// typedef  struct
        /// {
        ///     T_HIPC_NET_HEADER	   head;
        ///     T_HIPC_SYS_CONFIG	   sysConfig; //系统参数
        /// } T_HIPC_SYS_CONFIG_REQ, T_HIPC_SYS_CONFIG_RESP;
        /// typedef  struct
        /// {
        ///      Uint32  boardType;        //单板类型 0:编码 1：解码 
        ///      Uint32  sysTime;          //系统时间 
        ///      Uint8   devName[12];      //设备名称                                  
        /// } T_HIPC_SYS_CONFIG;
        /// </summary>
        [TestMethod]
        public void HIPC_CMD_SYS_CONFIG_GET_Test()
        {
            SocketHandler handler = new SocketHandler();
            T_HIPC_SYS_CONFIG_REQ request = new T_HIPC_SYS_CONFIG_REQ();
            request.head = new T_HIPC_NET_HEADER() { msgType = 0x8400 };
            request.sysConfig = new T_HIPC_SYS_CONFIG();
            T_HIPC_SYS_CONFIG_RESP response = handler.Handle<T_HIPC_SYS_CONFIG_RESP>(request);

            Assert.AreEqual(0x8401, response.head.msgType);
            Assert.IsTrue(0 <= response.sysConfig.boardType);
            Assert.IsTrue(response.sysConfig.boardType <= 1);
        }

        /// <summary>
        /// 消息		获取版本信息
        /// ID	请求:0x8402 应答：0x8403
        /// 方向	web，HipCodec ->编码盒，解码盒
        /// 参数	HIPC_CMD_SYS_VER_GET_REQ
        /// HIPC_CMD_SYS_VER_GET_RESP
        /// typedef  struct
        /// {
        ///     T_HIPC_NET_HEADER	   head;
        ///     Uint8  softVersion[3];        //软件版本 
        ///     Uint8  hardVersion;        //硬件版本
        ///     Uint8  pcbaVersion;        //pcba版本
        ///     Uint8  fpgaVersion[3];        //fpga版本
        /// } T_HIPC_SYS_VERSION_REQ, T_HIPC_SYS_VERSION_RESP;
        /// </summary>
        [TestMethod]
        public void HIPC_CMD_SYS_VER_GET_Test()
        {
            SocketHandler handler = new SocketHandler();
            T_HIPC_SYS_VERSION_REQ request = new T_HIPC_SYS_VERSION_REQ();
            request.head = new T_HIPC_NET_HEADER() { msgType = 0x8402 };
            T_HIPC_SYS_VERSION_RESP response = handler.Handle<T_HIPC_SYS_VERSION_RESP>(request);

            Assert.AreEqual(0x8403, response.head.msgType);
        }

        /// <summary>
        /// 消息		获取单板制造信息
        /// ID	请求:0x8404 应答：0x8405
        /// 方向	web，HipCodec ->编码盒，解码盒
        /// 参数	HIPC_CMD_SYS_PRO_INFO_GET_REQ
        /// HIPC_CMD_SYS_PRO_INFO_GET_RESP
        /// typedef  struct
        /// {
        ///     T_HIPC_NET_HEADER	   head;
        ///     T_HIPC_PRODUCT_INFO  productInfo;
        /// } T_HIPC_SYS_PROINFO_REQ, T_HIPC_SYS_PROINFO_RESP;
        /// typedef struct
        /// {
        ///     T_HIPC_EDID_DATE  date;      // 生产日期
        ///     Uint8 vender[16];   // 厂商
        ///     Uint8 seq[16];     // 序列号
        /// }T_HIPC_PRODUCT_INFO;
        /// </summary>
        [TestMethod]
        public void HIPC_CMD_SYS_PRO_INFO_GET_Test()
        {
            SocketHandler handler = new SocketHandler();
            T_HIPC_SYS_PROINFO_REQ request = new T_HIPC_SYS_PROINFO_REQ();
            request.head = new T_HIPC_NET_HEADER() { msgType = 0x8404 };
            T_HIPC_SYS_PROINFO_RESP response = handler.Handle<T_HIPC_SYS_PROINFO_RESP>(request);

            Assert.AreEqual(0x8405, response.head.msgType);
        }

        /// <summary>
        /// 消息		软复位请求
        /// ID	请求:0x8406 应答：0x8407
        /// 方向	web，HipCodec ->编码盒，解码盒
        /// 参数	HIPC_CMD_SYS_REBOOT_REQ
        /// HIPC_CMD_SYS_REBOOT_RESP
        /// typedef  struct
        /// {
        ///     T_HIPC_NET_HEADER	   head;
        /// } T_HIPC_SYS_REBOOT_REQ, T_HIPC_SYS_REBOOT_RESP;
        /// </summary>
        [TestMethod]
        public void HIPC_CMD_SYS_REBOOT_Test()
        {
            SocketHandler handler = new SocketHandler();
            T_HIPC_SYS_REBOOT_REQ request = new T_HIPC_SYS_REBOOT_REQ();
            request.head = new T_HIPC_NET_HEADER() { msgType = 0x8406 };
            T_HIPC_SYS_REBOOT_RESP response = handler.Handle<T_HIPC_SYS_REBOOT_RESP>(request);

            Assert.AreEqual(0x8407, response.head.msgType);
        }

        /// <summary>
        /// 消息		获取版本信息
        /// ID	请求:0x8408 应答：0x8409
        /// 方向	web，HipCodec ->编码盒，解码盒
        /// 参数	HIPC_CMD_NET_CONFIG_GET_REQ
        /// HIPC_CMD_NET_CONFIG_GET_RESP
        /// typedef  struct
        /// {
        ///     T_HIPC_NET_HEADER	   head;
        ///     Uint8  dhcp;   0：dhcp 1：静态ip地址                       
        ///     T_HIPC_NET_INFO netInfo;
        /// } T_HIPC_NET_CONFIG_REQ, T_HIPC_NET_CONFIG_RESP; 
        /// typedef struct
        /// {
        ///     Uint8 ipAddress[IP_CODEC_IP_LEN];          //ip地址
        ///     Uint8 netMask[IP_CODEC_IP_LEN];            //掩码
        ///     Uint8 gatway[IP_CODEC_IP_LEN];             //网关
        ///     Uint8 macAddress[IP_CODEC_IP_LEN];         //Mac地址
        /// }T_HIPC_NET_INFO;
        ///  #define    IP_CODEC_IP_LEN 20
        /// </summary>
        [TestMethod]
        public void HIPC_CMD_NET_CONFIG_GET_Test()
        {
            SocketHandler handler = new SocketHandler();
            T_HIPC_NET_CONFIG_REQ request = new T_HIPC_NET_CONFIG_REQ();
            request.head = new T_HIPC_NET_HEADER() { msgType = 0x8408 };
            T_HIPC_NET_CONFIG_RESP response = handler.Handle<T_HIPC_NET_CONFIG_RESP>(request);

            Assert.AreEqual(0x8409, response.head.msgType);
        }

        /// <summary>
        /// 消息		设置网络参数
        /// ID	请求:0x840a 应答：0x840b
        /// 方向	web，HipCodec ->编码盒，解码盒
        /// 参数	HIPC_CMD_NET_CONFIG_SET_REQ
        /// HIPC_CMD_NET_CONFIG_SET_RESP
        /// typedef  struct
        /// {
        ///     T_HIPC_NET_HEADER	   head;
        ///     Uint8  dhcp;   0：dhcp 1：静态ip地址                       
        ///     T_HIPC_NET_INFO netInfo;
        /// } T_HIPC_NET_CONFIG_REQ, T_HIPC_NET_CONFIG_RESP; 
        /// </summary>
        [TestMethod]
        public void HIPC_CMD_NET_CONFIG_SET_Test()
        {
            SocketHandler handler = new SocketHandler();
            T_HIPC_NET_CONFIG_REQ request = new T_HIPC_NET_CONFIG_REQ();
            request.head = new T_HIPC_NET_HEADER() { msgType = 0x840a };
            request.netInfo = new T_HIPC_NET_INFO() { };//TODO:
            T_HIPC_NET_CONFIG_RESP response = handler.Handle<T_HIPC_NET_CONFIG_RESP>(request);

            Assert.AreEqual(0x840b, response.head.msgType);
        }

        /// <summary>
        /// 消息		导出日志
        /// ID	请求: 0x840c应答：0x840d
        /// 方向	web，HipCodec ->编码盒，解码盒
        /// 参数	HIPC_CMD_SYS_LOG_EXPORT_REQ
        /// HIPC_CMD_SYS_LOG_EXPORT_RESP
        /// typedef struct
        /// {
        ///     T_HIPC_NET_HEADER    head;
        ///     Uint8 lenght;              //日志长度
        ///     Uint8 lastFlag;//  1:最后一包 0：不是最后一包
        ///     Uint8 context[LOG_MAX_SLICE];
        /// }T_HIPC_SYS_EXPORT_LOG_REQ,T_HIPC_SYS_EXPORT_LOG_RESP;
        /// #define LOG_MAX_SLICE  250
        /// </summary>
        [TestMethod]
        public void HIPC_CMD_SYS_LOG_EXPORT_Test()
        {
            SocketHandler handler = new SocketHandler();
            T_HIPC_SYS_EXPORT_LOG_REQ request = new T_HIPC_SYS_EXPORT_LOG_REQ();
            request.head = new T_HIPC_NET_HEADER() { msgType = 0x840c };
            T_HIPC_SYS_EXPORT_LOG_RESP response = handler.Handle<T_HIPC_SYS_EXPORT_LOG_RESP>(request);

            Assert.AreEqual(0x840d, response.head.msgType);
        }

        /// <summary>
        /// 消息		OSD设置
        /// ID	请求: 0x840e应答：0x840f
        /// 方向	VWAS，web，HipCodec ->编码盒，解码盒
        /// 参数	HIPC_CMD_SYS_OSD_CONFIG_REQ
        /// HIPC_CMD_SYS_OSD_CONFIG_RESP
        /// typedef  struct
        /// {
        ///     T_HIPC_NET_HEADER	   head;
        ///     Uint8    channel;
        ///     Uint8    enable;  //  0:close  1:open
        ///     Uint8    ipEnable;   //是否显示ip地址
        ///     Uint8    timeEnable; //是否显示时间
        ///     Uint8    color;           //颜色 0：白色 1：暂未定
        ///     Uint8    context[OSD_MAX_NUM]; //OSD内容， 汉字为gb2312编码
        /// } T_HIPC_OSD_CONFIG_REQ, T_HIPC_OSD_CONFIG_RESP;
        /// #define OSD_MAX_NUM    (48)
        /// </summary>
        [TestMethod]
        public void HIPC_CMD_SYS_OSD_CONFIG_Test()
        {
            SocketHandler handler = new SocketHandler();
            T_HIPC_OSD_CONFIG_REQ request = new T_HIPC_OSD_CONFIG_REQ();
            request.head = new T_HIPC_NET_HEADER() { msgType = 0x840e };
            T_HIPC_OSD_CONFIG_RESP response = handler.Handle<T_HIPC_OSD_CONFIG_RESP>(request);

            Assert.AreEqual(0x840f, response.head.msgType);
        }

        /// <summary>
        /// 消息		时间设置
        /// ID	请求: 0x8410应答：0x8411
        /// 方向	web，HipCodec ->编码盒，解码盒
        /// 参数	HIPC_CMD_SYS_TIME_SET_REQ
        /// HIPC_CMD_SYS_TIME_SET_RESP
        /// typedef  struct
        /// {
        ///     T_HIPC_NET_HEADER    head;
        ///     Uint8    ntpEnable;  //  0:close  1:open
        ///     Uint8    ntpServer[IP_CODEC_IP_LEN];   //ntp 服务器的ip地址
        ///     Uint32             cycleSec;//间隔周期 秒为单位
        ///     Uint16             timeZone; //时区
        ///     Uint16             port;//端口
        ///     T_SYS_TIME time;         //如果没有设置ntp，就设置RTC的时间 
        /// } T_HIPC_TIME_SET_REQ, T_HIPC_TIME_SET_RESP;
        /// typedef struct 
        /// {
        ///     Uint16  year;
        ///     Uint8   month;   /* scope is 1 - 12 */
        ///     Uint8   day;     /* scope is 1 - 31 */
        ///     Uint8   hour;    /* scope is 0 - 23 */
        ///     Uint8   minute;  /* scope is 0 - 59 */
        ///     Uint8   second;  /* scope is 0 - 59 */
        ///     //Uint8   week;    /* scope is 1 - 7  */ 
        /// }T_SYS_TIME;
        /// /*备注：如果打开了ntp，T_SYS_TIME  time设置无效，否则，通过该变量来设置rtc */
        /// </summary>
        [TestMethod]
        public void HIPC_CMD_SYS_TIME_SET_Test()
        {
            SocketHandler handler = new SocketHandler();
            T_HIPC_TIME_SET_REQ request = new T_HIPC_TIME_SET_REQ();
            request.head = new T_HIPC_NET_HEADER() { msgType = 0x8410 };
            T_HIPC_TIME_SET_RESP response = handler.Handle<T_HIPC_TIME_SET_RESP>(request);

            Assert.AreEqual(0x8411, response.head.msgType);
        }

        /// <summary>
        /// 消息		设置设备名称
        /// ID	请求: 0x841c应答：0x841d
        /// 方向	Web，HipCodec ->编码盒，解码盒
        /// 参数	HIPC_CMD_SYS_DEVNAME_SET_REQ
        /// HIPC_CMD_SYS_DEVNAME_SET_RESP
        /// typedef  struct
        /// {
        ///     T_HIPC_NET_HEADER      head;
        ///     Uint8            devName[12];            
        /// } T_HIPC_SYS_DEVNAME_REQ, T_HIPC_SYS_DEVNAME_RESP;
        /// </summary>
        [TestMethod]
        public void HIPC_CMD_SYS_DEVNAME_SET_Test()
        {
            SocketHandler handler = new SocketHandler();
            T_HIPC_SYS_DEVNAME_REQ request = new T_HIPC_SYS_DEVNAME_REQ();
            request.head = new T_HIPC_NET_HEADER() { msgType = 0x841c };
            T_HIPC_SYS_DEVNAME_RESP response = handler.Handle<T_HIPC_SYS_DEVNAME_RESP>(request);

            Assert.AreEqual(0x841d, response.head.msgType);
        }

        /// <summary>
        /// 消息		获取状态信息
        /// ID	请求: 0x841e应答：0x841f
        /// 方向	Web，HipCodec ->编码盒，解码盒
        /// 参数	HIPC_CMD_SYS_STATE_GET_REQ
        /// HIPC_CMD_SYS_STATE_GET_RESP
        /// typedef  struct
        /// {
        ///     T_HIPC_NET_HEADER      head;
        ///     Uint8   temperature;      //当前温度  
        ///     Uint16  runTime;       //系统运行时间
        ///     Uint16  runState;       //运行状态  
        ///     Uint8   cpuLoad;       //CPU占用率
        ///     Uint8   freeMem;       //空余内存         
        /// } T_HIPC_SYS_STATE_REQ, T_HIPC_SYS_STATE_RESP;
        /// </summary>
        [TestMethod]
        public void HIPC_CMD_SYS_STATE_GET_Test()
        {
            SocketHandler handler = new SocketHandler();
            T_HIPC_SYS_STATE_REQ request = new T_HIPC_SYS_STATE_REQ();
            request.head = new T_HIPC_NET_HEADER() { msgType = 0x841e };
            T_HIPC_SYS_STATE_RESP response = handler.Handle<T_HIPC_SYS_STATE_RESP>(request);

            Assert.AreEqual(0x841f, response.head.msgType);
        }

        /// <summary>
        /// 消息		时间获取
        /// ID	请求: 0x8420应答：0x8421
        /// 方向	web，HipCodec ->编码盒，解码盒
        /// 参数	HIPC_CMD_SYS_TIME_GET_REQ
        /// HIPC_CMD_SYS_TIME_GET_RESP
        /// typedef  struct
        /// {
        ///     T_HIPC_NET_HEADER    head;
        ///     Uint8    ntpEnable;  //  0:close  1:open
        ///     Uint8    ntpServer[IP_CODEC_IP_LEN];   //ntp 服务器的ip地址
        ///     Uint32             cycleSec;//间隔周期 秒为单位
        ///     Uint16             timeZone; //时区
        ///     Uint16             port;//端口
        ///     T_SYS_TIME time;         // 当前系统时间
        /// } T_HIPC_TIME_GET_REQ, T_HIPC_TIME_GET_RESP;
        /// </summary>
        [TestMethod]
        public void HIPC_CMD_SYS_TIME_GET_Test()
        {
            SocketHandler handler = new SocketHandler();
            T_HIPC_TIME_GET_REQ request = new T_HIPC_TIME_GET_REQ();
            request.head = new T_HIPC_NET_HEADER() { msgType = 0x8420 };
            T_HIPC_TIME_GET_RESP response = handler.Handle<T_HIPC_TIME_GET_RESP>(request);

            Assert.AreEqual(0x8421, response.head.msgType);
        }
    }
}
